class TG_BasePawn extends Pawn;

var() const DynamicLightEnvironmentComponent LightEnvironment;
var() const Name SwordHandSocketName;
var() const Name SwingAnimNode;

var() float HPT, HRT; //Health per Tick,Health Regeneration Time
var array<float> CurrentEnergy;
var() array<float> MaxEnergy; //1)Mana , 2)Rage , 3)Energy

var() enum EFaction
{
	Good,
	Evil,
	Neutral,
} Factions; //Tells the AI if it should attack


simulated event PostBeginPlay()
{
   Super.PostBeginPlay();
   Timers();
}

function GainEnergy(float AddedEnergy,int i)
{
    If(MaxEnergy[i]>CurrentEnergy[i])
    {
        if(CurrentEnergy[i]+AddedEnergy > MaxEnergy[i])
        {
        CurrentEnergy[i] = MaxEnergy[i];
        }
        else
        {
        CurrentEnergy[i] += AddedEnergy;
        }
    }
}

function Heal(float HealAmount)
{
    If(HealthMax>Health)
    {
        if(Health + HealAmount > HealthMax)
        {
        Health = HealthMax;
        }
        else
        {
        Health += HealAmount;
        }
    }	
}

//added a Timers Function,cause we could add diffrent resources here,also couldn't get the timer to be used with the Gain Rage with the variable
function Timers()
{
SetTimer(HRT, true,'RegenerateHealth');
}

//Used with the timer,can add diffrent functions for difrent resources
function RegenerateHealth()
{
    Heal(HPT);//HPT is rage per ticks,if we    want to modify the rage we gain in a tick

}

//Returns Aim Rotation
simulated singular event Rotator GetBaseAimRotation()
{
   local rotator POVRot, tempRot;

   tempRot = Rotation;
   tempRot.Pitch = 0;
   SetRotation(tempRot);
   POVRot = Rotation;
   POVRot.Pitch = 0;

   return POVRot;
}   

function UseEnergy(float EnergyCost,int i)
{
	if(CurrentEnergy[i] >= EnergyCost)
    {
    CurrentEnergy[i] -= EnergyCost;
    }
}

function float GetEnergy(int i)
{
	return CurrentEnergy[i];
}

simulated function PlayDying(class<DamageType> DamageType, vector HitLoc)
{
  local vector ApplyImpulse, ShotDir;
  
  bReplicateMovement = false;
  bTearOff = true;
  Velocity += TearOffMomentum;
  SetDyingPhysics();
  bPlayedDeath = true;
  HitDamageType = DamageType; // these are replicated to other clients
  TakeHitLocation = HitLoc;
  if ( WorldInfo.NetMode == NM_DedicatedServer )
  {
    GotoState('Dying');
    return;
  }
  InitRagdoll();
  mesh.MinDistFactorForKinematicUpdate = 0.f;
  
  if (Physics == PHYS_RigidBody)
  {
    //@note: Falling instead of None so Velocity/Acceleration don't get cleared
    setPhysics(PHYS_Falling);
  }
  PreRagdollCollisionComponent = CollisionComponent;
  CollisionComponent = Mesh;
  if( Mesh.bNotUpdatingKinematicDueToDistance )
  {
    Mesh.ForceSkelUpdate();
    Mesh.UpdateRBBonesFromSpaceBases(TRUE, TRUE);
  }
  if( Mesh.PhysicsAssetInstance != None )
  Mesh.PhysicsAssetInstance.SetAllBodiesFixed(False);
  Mesh.SetRBChannel(RBCC_Pawn);
  Mesh.SetRBCollidesWithChannel(RBCC_Default,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Pawn,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Vehicle,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Untitled3,True);
  Mesh.SetRBCollidesWithChannel(RBCC_BlockingVolume,TRUE);
  Mesh.ForceSkelUpdate();
  Mesh.UpdateRBBonesFromSpaceBases(TRUE, TRUE);
  Mesh.PhysicsWeight = 1.0;
  Mesh.bUpdateKinematicBonesFromAnimation=false;
  // mesh.bPauseAnims=True;
  Mesh.SetRBLinearVelocity(Velocity, false);
  mesh.SetTranslation(vect(0,0,1) * 6);
  Mesh.ScriptRigidBodyCollisionThreshold = MaxFallSpeed;
  Mesh.SetNotifyRigidBodyCollision(true);
  Mesh.WakeRigidBody();
  if( TearOffMomentum != vect(0,0,0) )
  {
    ShotDir = normal(TearOffMomentum);
    ApplyImpulse = ShotDir * DamageType.default.KDamageImpulse;
    // If not moving downwards - give extra upward kick
    if ( Velocity.Z > -10 )
    {
      ApplyImpulse += Vect(0,0,1)*2;
    }
    Mesh.AddImpulse(ApplyImpulse, TakeHitLocation,, true);
  }
  GotoState('Dying');
}

DefaultProperties
{
    Components.Remove(Sprite)

    Begin Object Class=DynamicLightEnvironmentComponent Name=TitanLightEnvironment
       bSynthesizeSHLight=true
       bIsCharacterLightEnvironment=true
       bUseBooleanEnvironmentShadowing=false
    End Object
    Components.Add(TitanLightEnvironment)
    LightEnvironment=TitanLightEnvironment

    Begin Object Class=SkeletalMeshComponent Name=TitanSkeletalMeshComponent
		bCacheAnimSequenceNodes=false
		AlwaysLoadOnClient=true
		AlwaysLoadOnServer=true
		CastShadow=true
		BlockRigidBody=true
		bUpdateSkelWhenNotRendered=true
		bIgnoreControllersWhenNotRendered=false
		bUpdateKinematicBonesFromAnimation=true
		bCastDynamicShadow=true
		RBChannel=RBCC_Untitled3
		RBCollideWithChannels=(Untitled3=true)
		bAcceptsDynamicDecals=false
		bHasPhysicsAssetInstance=true
		TickGroup=TG_PreAsyncWork
		MinDistFactorForKinematicUpdate=0.2f
		bChartDistanceFactor=true
		RBDominanceGroup=20
		bUseOnePassLightingOnTranslucency=true
		bPerBoneMotionBlur=true
    End Object
    Mesh=TitanSkeletalMeshComponent
    Components.Add(TitanSkeletalMeshComponent)
	bWorldGeometry=true
	HealthMax=100
	Health=100
    InventoryManagerClass=class'TG_InventoryManager'
}